package view;

import java.util.HashMap;
import java.util.Map;

import com.trolltech.qt.gui.QImage;
import com.trolltech.qt.gui.QTransform;

public class ImageLoader {
	private static ImageLoader istanza = null;
	// Metodo della classe impiegato per accedere al Singleton Yeah!
	public static synchronized ImageLoader get() {
		if (istanza == null) {istanza = new ImageLoader();}
		return istanza;
	}
	
	public static final String TAXIBG = "crazytaxi.jpg";
	public static final String ROAD = "road.png";
	public static final String BUILDING = "building.png";
	public static final String SIGHT = "sight.png";
	public static final String ARRIVE = "arrive.png";
	
	public static final String CAR = "car";	
	public static final String CARUP = "carup";
	public static final String CARLEFT = "carleft";
	public static final String CARRIGHT = "carright";
	
	public static final String CAR1 = "car_1.png";
	public static final String CAR2 = "car_2.png";
	public static final String CAR3 = "car_3.png";
	
	public static final String CARUP1 = "carup_1";
	public static final String CARLEFT1 = "carleft_1";
	public static final String CARRIGHT1 = "carright_1";
	
	public static final String CARUP2 = "carup_2";
	public static final String CARLEFT2 = "carleft_2";
	public static final String CARRIGHT2 = "carright_2";
	
	public static final String CARUP3 = "carup_3";
	public static final String CARLEFT3 = "carleft_3";
	public static final String CARRIGHT3 = "carright_3";
	
	

    
    private Map<String, QImage> imageBox;       

    public void init() {
        imageBox = new HashMap<String, QImage>();
        
        imageBox.put(TAXIBG, new QImage("images/"+TAXIBG));
        imageBox.put(ROAD, new QImage("images/"+ROAD));
        imageBox.put(BUILDING, new QImage("images/"+BUILDING));
        imageBox.put(SIGHT, new QImage("images/"+SIGHT));
        imageBox.put(ARRIVE, new QImage("images/"+ARRIVE));
        
//        imageBox.put(CAR, new QImage("images/"+CAR));
//        imageBox.put(CARUP,imageBox.get(CAR).transformed(new QTransform(-1, 0, 0, -1,1,1)));
//        imageBox.put(CARLEFT, imageBox.get(CAR).transformed(new QTransform(0, 1, -1, 0,1,1))  );
//        imageBox.put(CARRIGHT, imageBox.get(CAR).transformed(new QTransform(0, -1, 1, 0,1,1)) );
        
        imageBox.put(CAR1, new QImage("images/"+CAR1));
        imageBox.put(CARUP1,imageBox.get(CAR1).transformed(new QTransform(-1, 0, 0, -1,1,1)));
        imageBox.put(CARLEFT1, imageBox.get(CAR1).transformed(new QTransform(0, 1, -1, 0,1,1))  );
        imageBox.put(CARRIGHT1, imageBox.get(CAR1).transformed(new QTransform(0, -1, 1, 0,1,1)) );
        
        imageBox.put(CAR2, new QImage("images/"+CAR2));
        imageBox.put(CARUP2,imageBox.get(CAR2).transformed(new QTransform(-1, 0, 0, -1,1,1)));
        imageBox.put(CARLEFT2, imageBox.get(CAR2).transformed(new QTransform(0, 1, -1, 0,1,1))  );
        imageBox.put(CARRIGHT2, imageBox.get(CAR2).transformed(new QTransform(0, -1, 1, 0,1,1)) );
        
        imageBox.put(CAR3, new QImage("images/"+CAR3));
        imageBox.put(CARUP3,imageBox.get(CAR3).transformed(new QTransform(-1, 0, 0, -1,1,1)));
        imageBox.put(CARLEFT3, imageBox.get(CAR3).transformed(new QTransform(0, 1, -1, 0,1,1))  );
        imageBox.put(CARRIGHT3, imageBox.get(CAR3).transformed(new QTransform(0, -1, 1, 0,1,1)) );
        
    }

    public QImage getImage(final String key) {
    	return imageBox.get(key);
    }
}


